
                .syntax     unified
                .arch       armv7e-m
                .cpu        cortex-m4
                .fpu        softvfp
                .thumb

/*
;<h> 栈配置
;  <o> 栈大小 (字节) <0x0-0xFFFFFFFF:8>
;</h>
*/
                /* 设置栈大小为 64K */
                .equ        Stack_Size, 0x000020000
                /* 定义一个 stack段*/
                .section    .stack
                /* 2的3次方，8字节对齐*/
                .align      3
                .globl      __StackTop
                .globl      __StackLimit
__StackLimit:
                .space      Stack_Size
                .size       __StackLimit, . - __StackLimit
__StackTop:
                .size       __StackTop, . - __StackTop

/*
;<h> 中断向量表起始
*/
                .section    .vectors, "a", %progbits
                .align      2
                .type       __Vectors, %object
                .globl      __Vectors
                .globl      __Vectors_End
                .globl      __Vectors_Size
__Vectors:
                .long       __StackTop                         /*     栈顶 */
                .long       Reset_Handler                      /*     复位处理 */
                .long       NMI_Handler                        /* -14 NMI Handler */
                .long       HardFault_Handler                  /* -13 硬件错误处理 */
                .long       MemManage_Handler                  /* -12 MPU 错误处理 */
                .long       BusFault_Handler                   /* -11 总线错误处理 */
                .long       UsageFault_Handler                 /* -10 Usage Fault Handler */
                .long       0                                  /*     Reserved */
                .long       0                                  /*     Reserved */
                .long       0                                  /*     Reserved */
                .long       0                                  /*     Reserved */
                .long       SVC_Handler                        /*  -5 SVCall Handler */
                .long       DebugMon_Handler                   /*  -4 Debug Monitor Handler */
                .long       0                                  /*     Reserved */
                .long       PendSV_Handler                     /*  -2 PendSV Handler */
                .long       SysTick_Handler                    /*  -1 SysTick 处理 */

                /* 中断 */
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
                .long       IRQ00x_Handler
__Vectors_End:
                .equ        __Vectors_Size, __Vectors_End - __Vectors
                .size       __Vectors, . - __Vectors
/*
;<h> 中断向量表结尾
*/

/*
;<h> 复位处理起始
*/
                .section    .text.Reset_Handler
                .align      2
                .weak       Reset_Handler
                .type       Reset_Handler, %function
                .globl      Reset_Handler
Reset_Handler:
                /* 设置栈顶指针*/
                ldr         sp, =__StackTop
/* Single section scheme.
 *
 * The ranges of copy from/to are specified by following symbols
 *   __etext: LMA of start of the section to copy from. Usually end of text
 *   __data_start__: VMA of start of the section to copy to
 *   __data_end__: VMA of end of the section to copy to
 *
 * All addresses must be aligned to 4 bytes boundary.
 */
StackInit:
                /* 获取栈底*/
                ldr         r1, =__StackLimit
                /* 获取栈顶*/
                ldr         r2, =__StackTop

                movs        r0, 0
StackInitLoop:
                /* 把栈空间清0*/
                cmp         r1, r2           /* 比较栈顶和栈底地址*/
                itt         lt               /* lt(N != V； Z，C，N，V是程序状态寄存器中的位)， 满足则执行下面两条指令*/
                strlt       r0, [r1], #4     /* 把r0寄存器中的数据写入r1寄存器中的地址值中*/
                blt         StackInitLoop

ClrSramSR:
                /* 清除 SRAM 校验状态， 0x40050810 为 SRAM 校验状态寄存器，写1清0状态*/
                ldr         r0, =0x40050810
                //mov         r1, #0x1FF
                ldr         r1, =0x1FF
                str         r1, [r0]
CopyData:
                /* 从只读内存中复制数据到 RAM */
                ldr         r1, =__etext
                ldr         r2, =__data_start__
                ldr         r3, =__data_end__
CopyLoop:
                cmp         r2, r3
                ittt        lt               /* lt(N != V； Z，C，N，V是程序状态寄存器中的位)， 满足则执行下面两条指令*/
                ldrlt       r0, [r1], #4     /* 把__etext 地址的数据加载到 r0寄存器，并地址+4*/
                strlt       r0, [r2], #4     /* 把 r0寄存器里的值加载到 r2寄存器里的地址值，并地址+4*/
                blt         CopyLoop

CopyData1:
                ldr         r1, =__etext_ramb
                ldr         r2, =__data_start_ramb__
                ldr         r3, =__data_end_ramb__
CopyLoop1:
                cmp         r2, r3
                ittt        lt                /* lt(N != V； Z，C，N，V是程序状态寄存器中的位)， 满足则执行下面两条指令*/
                ldrlt       r0, [r1], #4      /* 把__etext_ramb 地址的数据加载到 r0寄存器，并地址+4*/
                strlt       r0, [r2], #4      /* 把 r0寄存器里的值加载到 r2寄存器里的地址值，并地址+4*/
                blt         CopyLoop1
                /* 清除 BSS 段*/
ClearBss:
                ldr         r1, =__bss_start__
                ldr         r2, =__bss_end__

                movs        r0, 0
ClearLoop:
                cmp         r1, r2                 /* 比较 BSS 段起始地址和结束地址*/
                itt         lt                     /* lt(N != V； Z，C，N，V是程序状态寄存器中的位)， 满足则执行下面两条指令*/
                strlt       r0, [r1], #4           /* 把r0寄存器中的数据写入r1寄存器中的地址值中*/
                blt         ClearLoop
                /* 清除 Ramb 中的 BSS 数据*/
ClearBss1:
                ldr         r1, =__bss_start_ramb__
                ldr         r2, =__bss_end_ramb__

                movs        r0, 0
ClearLoop1:
                cmp         r1, r2                 /* 比较 Ramb BSS 段起始地址和结束地址*/
                itt         lt                     /* lt(N != V； Z，C，N，V是程序状态寄存器中的位)， 满足则执行下面两条指令*/
                strlt       r0, [r1], #4           /* 把r0寄存器中的数据写入r1寄存器中的地址值中*/
                blt         ClearLoop1

                /* 调用系统初始化函数*/
                bl          system_init
                /* 调用应用入口 */
                bl          main
                bx          lr
                .size       Reset_Handler, . - Reset_Handler
/*
;<h> 复位处理结束
*/

/*
;<h> 默认处理函数起始
*/
                .section    .text.Default_Handler, "ax", %progbits
                .align      2
Default_Handler:
                b           .
                .size       Default_Handler, . - Default_Handler
/*
;<h> 默认处理函数结束
*/
